package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.ITrainingDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.Training;
import com.hy.erp.inventory.pojo.interfaces.ITraining;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.ITrainingService;

/**
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-12；时间：下午12:01:10</li>
 * <li>字段类型：long；字段名称：serialVersionUID</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("trainingService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class TrainingService
							extends
							AbstractBusinessService < ITraining >
																	implements
																	ITrainingService
{

	
	private static final long	serialVersionUID	=
														8448591920318952932L ;
	public TrainingService()
	{
		super ( );
	}

	@ Override
	public String[] addTraining (
									Object[] training )
	{
		if(training==null)
		{
			return null;
		}
		else
		{
			ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
			Training[] trainings=new Training[training.length];
			for ( int i =
							0 ; i < training.length ; i ++ )
			{
				Training training2=( Training ) training[i];
				trainings[i]=training2;
			}
			
			return dao.persist ( trainings ) ;
		}
	}

	@ Override
	public Integer removeTraining (
									String [ ] trainIds )
	{
		if ( ( null == trainIds )
			     || ( trainIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
				return dao.remove ( trainIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyTraining (
									Training training )
	{
		if ( ( null == training ) || ( null == training.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
			ITraining iTraining= training;
			if ( null == iTraining)
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iTraining )!=null) ;
		}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < ITraining > getTrainingById (
												String [ ] Id )
	{
		if((Id.length!=0)||Id!=null)
		{
			ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
			return dao.findByIdentifier ( Id );
		}
		return null ;
	}

	@ Override
	public List < ITraining > getAllTraining ( )
	{
		ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
		return dao.find ( ) ;
	}

	@ Override
	public List < ITraining > getTrainingByQueryName (
														String queryName ,
														Object [ ] args )
	{
		ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
		return dao.findByNamedQuery ( queryName , args ) ;
	}

	@ Override
	public String [ ] modifyTraining (
										Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			ITrainingDao dao=( ITrainingDao ) this.getDao ( ITraining.class );
			Training[] types=new Training[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	Training type=( Training ) objects[i];
            	types[i]=type;
            }
			
			return dao.merge ( types );
		}
	}
	
	

}
